package com.jhs.kjs.robot;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.ApplicationEvent;
import org.springframework.context.ApplicationListener;

import com.jhs.kjs.robot.core.ECoord2AddrBatch;
import com.jhs.kjs.robot.service.ICoord2AddrService;
import com.jhs.kjs.robot.web.IConnectWeb;
import com.jhs.kjs.robot.web.IMakeUrl;
import com.jhs.kjs.robot.web.daum.DaumConnect;
import com.jhs.kjs.robot.web.daum.DaumMakeUrl;

public class Coord2AddrRobot implements ApplicationListener<ApplicationEvent> {
	// 변수와 setter를 선언하여 bean xml 로부터 값을 넘겨받을 수 있다.
	private static String apikey;
	
	private IMakeUrl urlMaker;
	private IConnectWeb connect;
	private ECoord2AddrBatch batche;
	private int sleepTime;
	public int getSleepTime() {
		return sleepTime;
	}

	public void setSleepTime(int sleepTime) {
		this.sleepTime = sleepTime;
	}

	@Autowired
	private ICoord2AddrService coord2AddrService;

	public void setCoord2AddrService(ICoord2AddrService coord2AddrService) {
		this.coord2AddrService = coord2AddrService;
	}

	public static String getApikey() {
		return apikey;
	}

	public void setApikey(String apikey) {
		Coord2AddrRobot.apikey = apikey;
	}
	public void init(){

		urlMaker = new DaumMakeUrl(getApikey());
		connect = new DaumConnect();
		Coord2AddrThread robot = new Coord2AddrThread();
		batche = ECoord2AddrBatch.MACHINE;
		
		batche.setCoord2AddrService(coord2AddrService);
		batche.setUrlMaker(urlMaker);
		batche.setConnect(connect);
		robot.setSleepTime(getSleepTime());
		robot.setBatch(batche);
		robot.start();
		
	}
	
	public ECoord2AddrBatch getBatche() {
		return batche;
	}

	public void setBatche(ECoord2AddrBatch batche) {
		this.batche = batche;
	}

	@Override
	public void onApplicationEvent(ApplicationEvent arg0) {
		
	}

}
